<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Setting;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;

class SettingController extends Controller
{
    public function lists(Request $request): JsonResponse
    {
        return $this->success(Setting::get());
    }

    public function updateOrCreate(Request $request): JsonResponse
    {
        $lists = $request->input();
        foreach ($lists as $k => $v) {
            $res = Setting::query()->updateOrCreate(
                ['key' => $k],
                [
                    'value' => $v,
                ]
            );
        }
        return $this->success($res);
    }
}
